package com.gcb.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 创建方式
 *
 * @author tdl
 * @since 2024-04-10
 */
@Getter
public enum CreateTypeEnum {
    OPERATION(1, "运营创建"), USER(2, "用户自建");

    private final Integer code;
    private final String info;

    CreateTypeEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }

    public static String getInfo(String type) {
        Integer i = Optional.ofNullable(type)
                .map(Integer::parseInt)
                .orElse(-1);
        return Optional.ofNullable(of(i))
                .map(CreateTypeEnum::getInfo)
                .orElse("");
    }

    public static String getInfo(Integer type) {
        return Optional.ofNullable(of(type))
                .map(CreateTypeEnum::getInfo)
                .orElse("");
    }

    public static CreateTypeEnum of(Integer code) {
        Optional<CreateTypeEnum> first = Arrays.stream(CreateTypeEnum.values()).filter(v -> v.getCode().equals(code)).findFirst();
        return first.orElse(null);
    }
}
